<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<%@ include file="/WEB-INF/views/include/easyui.jsp"%>
</head>
<body class="easyui-layout" style="font-family: '微软雅黑'">
	<div data-options="region:'west',split:true,border:false,title:'字典列表'"  style="width: 300px">
		<table id="dictDg"></table>
    </div>
    <div data-options="region:'center',split:true,border:false,title:'字典内容'">
    	<shiro:hasRole name="admin">
    	<div id="tg_tb" style="padding:5px;height:auto">
		    <div>
		    	<shiro:hasPermission name="sys:perm:add">
		    	<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-add" onclick="add()">添加</a>
		    	<span class="toolbar-item dialog-tool-separator"></span>
		    	</shiro:hasPermission>
		        <shiro:hasPermission name="sys:perm:delete">
		        <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-remove" onclick="del()" id="delBtn">删除</a>
		        <span class="toolbar-item dialog-tool-separator"></span>
		        </shiro:hasPermission>
		        <shiro:hasPermission name="sys:perm:update">
		        <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-edit" onclick="upd()" id="updBtn">修改</a>
		        <span class="toolbar-item dialog-tool-separator"></span>
		        </shiro:hasPermission>
		    </div>
		</div>
		</shiro:hasRole>
		<form id="listForm" action="${ctx}/system/dict/update" method="post">
			<table  class="formTable">
				<tr>
					<td>字典名：</td>
					<td>
						<input type="hidden" name="id" value="${id }" />
						<input id="listLabel" name="label" type="text" value="${dict.label }" class="easyui-validatebox" style="background-color: #EBEBE4" required="required" readonly="readonly"/>
					</td>
				</tr>
				<tr>
					<td>字典码：</td>
					<td>
						<input type="hidden" name="id" value="${id }" />
						<input id="listCode" name="code" type="text" value="${dict.code }" class="easyui-validatebox" style="background-color: #EBEBE4" required="required" readonly="readonly"/>
					</td>
				</tr>
				<tr>
					<td>字典值：</td>
					<td><input id="listValue" name="value" type="text" value="${dict.value }" class="easyui-validatebox" style="background-color: #EBEBE4" required="required" readonly="readonly"/></td>
				</tr>
				<tr>
					<td>描述：</td>
					<td><textarea rows="2" id="listDesc" cols="41" name="description" style="font-size: 12px;font-family: '微软雅黑'" disabled="disabled">${dict.description}</textarea></td>
				</tr>
			</table>
			<div style="padding-left:100px;padding-top:20px;height:auto" id="btnBox">
				<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-ok" onclick="confirmUpd()">确认</a>
				<span class="toolbar-item dialog-tool-separator"></span>
				<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-cancel" onclick="cancelUpd()">取消</a>
				<span class="toolbar-item dialog-tool-separator"></span>
			</div>
		</form>
    </div>
<div id="dlg"></div>
<div id="icon_dlg"></div>

<script type="text/javascript">
var dictData;
var d;
var dictDg;
var menuId=0;
var parentPermId;
$(function(){
    $('#listForm').form({
        onSubmit: function(){
            var isValid = $(this).form('validate');
            return isValid;	// 返回false终止表单提交
        },
        success:function(data){
            successTip(data, dictDg, null);
            lockUpd();
        }
    });

    dictInit();

    dictDg=$('#dictDg').treegrid({
	method: "get",
    url:'${ctx}/system/dict/jsonForList',
    fit : true,
	fitColumns : true,
	border : false,
	idField : 'id',
	treeField:'label',
	parentField : 'pid',
	iconCls: 'icon',
	animate:true,
	rownumbers:true,
	singleSelect:true,
	striped:true,
    columns:[[
        {field:'id',title:'id',hidden:true},
        {field:'label',title:'名称',width:100}
    ]],
    enableHeaderClickMenu: false,
    enableHeaderContextMenu: false,
    enableRowContextMenu: false,
    dataPlain: true,
    onClickRow:function(rowData){
        dictId=rowData.id;
    	commonAjax('${ctx}/system/dict/jsonById', {dictId:dictId }, null, function(data){
    	    if(!isBlank(data)){
                dictData = data;
                unlockOpt();
                loadFormData('#listForm', data, '');
			}
        });
    }
	});
});

function dictInit() {
    $('#listForm').hide();
    $('#btnBox').hide();
    $('#delBtn').linkbutton('disable');
    $('#updBtn').linkbutton('disable');
}

function unlockOpt() {
    $('#listForm').show();
    $('#delBtn').linkbutton('enable');
    $('#updBtn').linkbutton('enable');
}

function unlockUpd(){
    $('#btnBox').show();
    $('#listLabel').css('background-color', '#fff');
    $('#listCode').css('background-color', '#fff');
    $('#listValue').css('background-color', '#fff');
    $('#listLabel').removeAttr('readonly');
    $('#listCode').removeAttr('readonly');
    $('#listValue').removeAttr('readonly');
    $('#listDesc').removeAttr('disabled');
}

function lockUpd(){
    $('#btnBox').hide();
    $('#listLabel').css('background-color', '#EBEBE4');
    $('#listCode').css('background-color', '#EBEBE4');
    $('#listValue').css('background-color', '#EBEBE4');
    $('#listLabel').attr('readonly', 'readonly');
    $('#listCode').attr('readonly', 'readonly');
    $('#listValue').attr('readonly', 'readonly');
    $('#listDesc').attr('disabled', 'disabled');
}

//弹窗增加
function add() {
    var dict_pid;
    var row = dictDg.datagrid('getSelected');
    if(rowIsNullWithOutTip(row)) {
        dict_pid = 0;
    }else{
        dict_pid = row.id;
	}
    d=$("#dlg").dialog({
        title: '添加字典',
        width: 380,
        height: 360,
        href:'${ctx}/system/dict/create/' + dict_pid,
        maximizable:true,
        modal:true,
        buttons:[{
            text:'确认',
            handler:function(){
                $("#mainform").submit();
            }
        },{
            text:'取消',
            handler:function(){
                d.panel('close');
            }
        }]
    });
}

//删除
function del(){
    var row = dictDg.datagrid('getSelected');
    if(rowIsNull(row)) return;
	parent.$.messager.confirm('提示', '删除后无法恢复您确定要删除？', function(data){
        if (data){
            $.ajax({
                type:'get',
                url:"${ctx}/system/dict/delete/"+row.id,
                success: function(data){
                    successTip(data);
                    dictDg.treegrid('reload');
                    dictInit();
                }
            });
        }
    });
}

//修改
function upd(){
	var row = dictDg.datagrid('getSelected');
	if(rowIsNull(row)) return;
    unlockUpd();
}

//确认修改
function confirmUpd(){
    $("#listForm").submit();
}

//取消修改
function cancelUpd(){
    lockUpd();
}

</script>
</body>
</html>